import 'package:flutter/material.dart';
import 'package:flutter_ad_demo/channel/NativeMethodChannel.dart';
import 'package:flutter_ad_demo/widget/SimpleWidget.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter广告示例'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            _createSplashAdBtn(),
            const Padding(padding: EdgeInsets.only(top: 16)),
            _createInterstitialAdBtn(),
          ],
        ),
      ),
    );
  }

  /// 构建开屏广告按钮
  Widget _createSplashAdBtn() => SimpleWidget(
        width: 120,
        height: 40,
        alignment: Alignment.center,
        decoration: const BoxDecoration(color: Colors.blue),
        onTap: () {
          /// 通知原生端获取开屏广告
          NativeMethodChannel.showSplashAd();
        },
        child: const Text(
          "开屏广告",
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        ),
      );

  /// 构建插屏广告按钮
  Widget _createInterstitialAdBtn() => SimpleWidget(
        width: 120,
        height: 40,
        alignment: Alignment.center,
        decoration: const BoxDecoration(color: Colors.blue),
        onTap: () {
          /// 通知原生端获取插屏广告
          NativeMethodChannel.showInterstitialAd();
        },
        child: const Text(
          "插屏广告",
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        ),
      );
}
